import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-04-05
 * Time: 10:15
 */
public class TcpEchoClient {
private Socket socket=null;

    public TcpEchoClient(String serverIp ,int port) throws IOException {
        socket= new Socket(serverIp,port);
    }
    public void  start(){
        Scanner scanner = new Scanner(System.in);
        try {InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();
            PrintWriter printWriter = new PrintWriter(outputStream);
            Scanner scannerFromSocket =new Scanner(inputStream);
while (true){
    System.out.println("请输入请求->");
    String request = scanner.next();
    printWriter.println(request);
    String response = scannerFromSocket.next();
    System.out.println("请求为"+request+"响应为"+response);
}
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        TcpEchoClient tcpEchoClient = new TcpEchoClient("127.0.0.1",6666);
        tcpEchoClient.start();
    }
}
